package com.example.abe.diandi.trends.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.abe.diandi.R;
import com.example.abe.diandi.trends.model.TrendModel;

import example.abe.com.framework.recycleview.base.ItemViewDelegate;
import example.abe.com.framework.recycleview.base.ViewHolder;
import example.abe.com.framework.util.TimeUtil;

import static example.abe.com.framework.util.TimeUtil.WEEK_FORMAT_2;

/**
 * Created by abe on 17/3/19.
 */

public class SearchTrendDelegate implements ItemViewDelegate<TrendModel> {

    @Override
    public boolean isForViewType(TrendModel item, int position) {
        return true;
    }

    @Override
    public View getItemView(Context context, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_collect_trend, parent, false);
        return view;
    }

    @Override
    public void bindViewHolder(ViewHolder holder, TrendModel t, int position) {
        //设置位置信息
        holder.getItemView().setTag(position);
        //设置数据
        holder.setText(R.id.item_collect_trend_title, t.getTitle());
        holder.setText(R.id.item_collect_trend_content, TextUtils.isEmpty(t.getContent()) ? "点击查看图片详情" :t.getContent());
        holder.setText(R.id.item_collect_trend_date, TimeUtil.getStrTimeCH(t.getTime(), "dd"));
        holder.setText(R.id.item_collect_trend_week, TimeUtil.getWeek(t.getTime(), WEEK_FORMAT_2));
    }
}
